package interview10;

/**
 * @author Jack
 * @date 2019-11-06-15:57
 * 青蛙跳台阶问题(变形的斐波那契数列问题)
 */
public class Solution2 {

    public int jumpToNStep(int n){
        if(n <= 0){return 0;}
        if(n == 1 || n == 2){return n;}
        int maxStepToPreviousTwo = 1;
        int maxStepToPreviousOne = 2;
        int maxStepToN = 0;
        for (int i = 3; i <= n; i++){
            maxStepToN = maxStepToPreviousOne + maxStepToPreviousTwo;
            if(i == n){break;}
            maxStepToPreviousTwo = maxStepToPreviousOne;
            maxStepToPreviousOne = maxStepToN;
        }
        return maxStepToN;
    }

}
